<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Journal extends Model
{
    const JOURNAL_ID = 2;
    protected $table = 'journals';


    public function issue()
    {
        return $this->hasOne(Issue::class);
    }


    public function news()
    {
        return $this->hasMany(News::class);
    }

    public function newscat()
    {
        return $this->hasMany(NewsCat::class);
    }


    public function setQrCodeAttribute($imgs)
    {
        if (is_array($imgs)) {
            $this->attributes['qr_code'] = json_encode($imgs);
        }
    }
    
    public function getQrCodeAttribute()
    {
        // print_r(json_decode($this->attributes['qr_code'], true));exit;
        return json_decode($this->attributes['qr_code'], true);
    }

    public static function currentJournal()
    {
        return (new static())->first();
    }
}
